import { createRouter, createWebHistory } from 'vue-router'
//!createRouter 创建路由实例
//!createWebHistory 创建history路由
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: () => import('@/views/Layout/index.vue'),
      children: [
        {
          path: '',
          name: 'Home',
          component: () => import('@/views/Home/index.vue'),
        },
        {
          path: '/Category/:id',
          name: 'Category',
          component: () => import('@/views/Category/index.vue'),
        },
        {
          path: '/Category/sub/:id',
          name: 'SubCategory',
          component: () => import('@/views/SubCategory/index.vue'),
        },
        {
          path: '/Detail/:id',
          name: 'Detail',
          component: () => import('@/views/Detail/index.vue'),
        },
        {
          path: '/CartList',
          name: 'CartList',
          component: () => import('@/views/CartList/index.vue'),
        },
        {
          path: '/Checkout',
          name: 'Checkout',
          component: () => import('@/views/Checkout/index.vue'),
        },
        {
          path: '/Pay',
          name: 'Pay',
          component: () => import('@/views/Pay/index.vue'),
        },
        {
          path: 'payResult',
          name: 'payResult',
          component: () => import('@/views/Pay/PayBack.vue'),
        },
        {
          path: '/Member',
          name: 'Member',
          component: () => import('@/views/Member/index.vue'),
          children: [
            {
              path: '',
              component: () => import('@/views/Member/components/UserInfo.vue'),
            },
            {
              path: 'order',
              component: () => import('@/views/Member/components/UserOrder.vue'),
            }
          ]
        },

      ]
    },
    {
      path: '/login',
      name: 'login',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('@/views/Login/index.vue')
    }
  ],
  //！路由滚动行为定制
  scrollBehavior(to, from, savedPosition) {
    return { top: 0 }
  }
})

export default router
